In [ ]:
# Requires GLPlot
using ApproxFun

Heat equation with Dirichlet $$u_t = \Delta u, u(\pm 1,y,t)=u(x,\pm 1,t)=0$$


In [ ]:
# domain is a square
d=Interval()^2
# initial condition
u0   = Fun((x,y)->exp(-40(x-.1)^2-40(y+.2)^2)+.5exp(-30(x+.5).^2-40(y+.2).^2),d)
# dirichlet boundary conditions
B=dirichlet(d)

Δ=lap(d)
h=0.0001 # time step
timeevolution(B,Δ,u0,h);

Advection-diffusion with Dirichlet $$u_t = 0.01 \Delta u -4 u_x -3 u_y, u(\pm 1,y,t)=u(x,\pm 1,t)=0$$


In [ ]:
d=Interval()^2
u0   = Fun((x,y)->exp(-40(x-.1)^2-40(y+.2)^2),d)
B=dirichlet(d)
D=Derivative(Interval())
L=(0.01D^2-4D)I + I(0.01D^2-3D)
h=0.002
timeevolution(B,L,u0,h)

Wave equation with Dirichlet $$u_{tt} = \Delta u, u(x,y,0)=u_0(x,y), u(\pm 1,y,t)=u(x,\pm 1,t)=0$$


In [ ]:
# domain is a square
d=Interval()^2

# initial condition
u0   = Fun((x,y)->exp(-50x^2-40(y-.1)^2)+.5exp(-30(x+.5)^2-40(y+.2)^2),d)

# dirichlet boundary conditions, try neumann(d).  mixed is also possible
B= dirichlet(d)   
Δ=lap(d)
h = 0.005

# the 2 specifies that we are solving a second order equation
# the default is to take u_t(x,0)=0
timeevolution(2,B,Δ,u0,h)

Wave equation with Dirichlet-Neumann $$u_{tt} = \Delta u, u(x,y,0)=u_0(x,y), u(-1,y,t)=u_x(1,y,t)=u(x,\pm 1,t)=0$$


In [ ]:
h    = 0.005
# initial condition
d=Interval()^2
u0   = Fun((x,y)->exp(-50x.^2-40(y-.1).^2)+.5exp(-30(x+.5).^2-40(y+.2).^2),d)

dx=d[1];dy=d[2]
B= [[ldirichlet(dx),rneumann(dx)]I,Idirichlet(dy)]   

Δ=lap(d)

timeevolution(2,B,Δ,u0,h)

Klein–Gordon equation with Dirichlet $$u_{tt} = \Delta u - 100u, u(x,y,0)=u_0(x,y), u(\pm 1,y,t)=u(x,\pm 1,t)=0$$


In [ ]:
d=Interval()^2
# initial condition
u0   = Fun((x,y)->exp(-50x.^2-40(y-.1).^2)+.5exp(-30(x+.5).^2-40(y+.2).^2),d)
B= dirichlet(d) 

L=lap(d)-100I

h    = 0.003
timeevolution(2,B,L,u0,h)

Sine Gordon


In [ ]:
d=Interval()^2
# initial condition
u0   = Fun((x,y)->2.exp(-50x^2-50y^2),d)
B= dirichlet(d) 

L=lap(d)-I
g(u)=u-sin(u)

h    = 0.0024
timeevolution(2,B,L,g,u0,h)

In [ ]: